<?php

namespace App\Module\Api\Controllers;
use App\Exceptions\Customize\ParamsException;
use App\Module\Api\Controllers\Request\QueryIdRequest;
use App\Module\Api\Validator\CommonIdValidator;
use App\Module\Api\Validator\OrderDetailsValidator;
use App\System\Base\Services\TokenService;
use App\System\Oms\Repositories\OrderInfoRepository;
use App\System\Order\Repositories\OrderGoodsRepository;


/**
 * 订单详细
 * @package App\Module\Admin\Controllers
 */
class OrderDetailsController extends Controller
{
    public function __construct()
    {
        $this->query = new QueryIdRequest();
        parent::__construct();
    }

    public function index()
    {
        $user_id=checkSession();
        (new OrderDetailsValidator())->check();
        $action = $this->query->action;
        $id = $this->query->orderId;
        if ($action == 1 ){
            //课程订单
            $order = OrderGoodsRepository::getInstance();
            $order_info = $order->getOneOrder($id,$user_id);
        }elseif($action == 2){
            //活动订单
//11
        }else{
            //赠送订单
        }
        if(!$order_info)
        {
            throw new ParamsException([
                'error_code' => '1011',
                'message'    => '订单不存在或已经删除',
            ]);
        }
        return apiResponse(['order'=>$order_info]);
    }
}
